package com.mesSystem.service.impl.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mesSystem.entity.Process;
import com.mesSystem.entity.ProcessRoute;
import com.mesSystem.mapper.ProcessRouteMapper;
import com.mesSystem.service.impl.ProcessRouteService;
import com.mesSystem.service.impl.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProcessRouteServiceImpl extends ServiceImpl<ProcessRouteMapper, ProcessRoute> implements ProcessRouteService {

    @Autowired
    ProcessService processService;
    /**
     * 根据工艺id取得该工艺路线中工序信息的集合
     *
     * @param processRouteId
     * @return
     */
    public List<Process> queryProcessByProcessRouteId(Long processRouteId) {
        String processListJson = getById(processRouteId).getProcessList();

        List<Long> processList = JSONUtil.toList(processListJson,Long.class);

        // 根据工序列表查询工序信息
        if (!processList.isEmpty()) {
            QueryWrapper<Process> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("process_id", processList);
            return processService.list(queryWrapper);
        } else {
            // 处理工序列表为空的情况
            return Collections.emptyList();
        }
    }
}
